<!-- 结算送审-提交页面 && 项目操作-结算送审 -->
<template>
  <div>
    <div style="padding: 15px 25px 0px; width: 100%">
      <!-- 基本信息 -->
      <jn-prj-detail :prj-id="prjId" :prj-type="prjType" />
      <!-- 项目站址信息 -->
      <jn-site-detail :prj-id="prjId" />
      <!-- 项目专属信息 -->
      <jn-proprietary-detail :prj-id="prjId" :prj-type="prjType" />
      <TCollapse title="采购订单调整情况">
        <el-tabs v-model="activeName" style="width: 100%;" type="border-card" @tab-click="handleClick(activeName)">
          <el-tab-pane label="物资明细信息" name="1">
            <MyTable
              id="MyTableId"
              ref="myTableRef"
              :table-data="tableData"
              :columns="colOption"
              :col-option-enum="dicLists"
              :is-selection="false"
              class="table-container"
            />
          </el-tab-pane>
          <el-tab-pane label="服务明细信息" name="2">
            <MyTable
              id="MyTableId"
              ref="myTableRef"
              :table-data="tableDataTwo"
              :columns="colOptionTwo"
              :col-option-enum="dicLists"
              :is-selection="false"
            />
          </el-tab-pane>
        </el-tabs>
      </TCollapse>
      <!-- 附件 -->
      <TCollapse title="附件">
        <iframe ref="myIframeFjRef" style="width: 100%" frameborder="0" scrolling="no" :src="fuJianSrc" />
      </TCollapse>
      <!-- 我承诺 -->
      <div v-show="promiseTextShow" class="borderStyle">
        <div class="promiseText">
          <div class="red promiseBot">
            请先核实订单信息是否已更新为调整后的内容。若订单信息不正确，刷新页面（关闭后再次打开页面）后系统会重新获取商合订单信息详情。若多次操作后订单信息仍不正确请咨询商合交易系统进行核实（提供项目编码与订单号）。
          </div>
          <div class="promiseBot">
            <span class="red">*</span> 是否建议结算审计必审
            <el-select
              v-model="promiseValue"
              :disabled="promiseDisb"
              style="width: 100px; height: 20px"
              placeholder="请选择"
            >
              <el-option
                v-for="item in promiseOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
                style="height: 20px"
              />
            </el-select>
          </div>
          <div>
            <el-radio v-model="promiseRadio" :disabled="promiseRadioDisb" label="1"><span
              style="color: black"
            >承诺：已审核确认该项目工程价款结算金额与商务平台订单金额一致，在线工程竣工档案资料完整齐全。区域勾选后，提交按钮才能操作。</span></el-radio>
          </div>
        </div>
      </div>
      <!-- 底部按钮 -->
      <FooterButton
        :button-disable="buttonDisable"
        @handleClose="handleClose"
        @updateDatas="updateDatas"
        @revocation="revocation"
      />
    </div>
  </div>
</template>

<script>
import TCollapse from '@/components/basic/TCollapse.vue'
import { getQueryObject } from '@/utils' // 获取url地址信息
import MyTable from '@/components/basic/myTable'
// import * as Common from '@/api/common'
import {
  getWFWorkItem,
  queryAdjustEquipsList,
  queryAdjustServListNew,
  getPrjDetail,
  queryPushAudit,
  queryIfRetractAudit,
  updateAduitDatas
} from '@/api/actualBudget/communicationSubmitApproval'
import { clonePage } from '@/utils'
// 展示信息
import JnPrjDetail from '@/components/jn/JnPrjDetail.vue'
import JnSiteDetail from '@/components/jn/JnSiteDetail.vue'
import JnProprietaryDetail from '@/components/jn/JnProprietaryDetail.vue'
import FooterButton from '@/components/footer/details'

// 列表表头配置
const colOption = [
  { label: '站址编码', width: '90', prop: 'siteCode' },
  { label: '站址名称', width: '90', prop: 'siteName' },
  { label: '采购订单号', width: '90', prop: 'orderCode' },
  { label: '供应商编码', width: '90', prop: 'supplyCode' },
  { label: '供应商名称', width: '90', prop: 'supplyName' },
  { label: '合同编码', width: '90', prop: 'contractCode' },
  { label: '合同名称', width: '90', prop: 'contractName' },
  { label: '子专业名称', width: '90', prop: 'subSpec' },
  { label: '物资编码', width: '90', prop: 'pmsMaterialCode' },
  { label: '物资名称', width: '90', prop: 'pmsMaterialName' },
  { label: '规格', width: '90', prop: 'formPattern' },
  { label: '单位', width: '90', prop: 'unit' },
  { label: '单位计量', width: '90', prop: 'dwjl' },
  { label: '数量', width: '90', prop: 'mdseNum' },
  { label: '不含税单价(元)', width: '90', prop: 'price' },
  { label: '不含税总价(元)', width: '90', prop: 'equipSum' },
  { label: '税率(%)', width: '90', prop: 'mdseTaxRate' },
  { label: '税额(元)', width: '90', prop: 'mdseTax' },
  { label: '含税总价（元）', width: '90', prop: 'equipTaxSum' }
]

// 列表表头配置
const colOptionTwo = [
  { label: '站址编码', width: '90', prop: 'siteCode' },
  { label: '站址名称', width: '90', prop: 'siteName' },
  { label: '采购订单号', width: '90', prop: 'orderCode', dicType: 'PROJ_TYPE', dicProp: { label: 'dictName', value: 'dictId' }},
  { label: '供应商编码', width: '90', prop: 'supplyCode' },
  { label: '供应商名称', width: '90', prop: 'supplyName' },
  { label: '合同编码', width: '90', prop: 'contractCode' },
  { label: '合同名称', width: '90', prop: 'contractName' },
  { label: '子专业名称', width: '90', prop: 'subSpec' },
  { label: '服务编码', width: '90', prop: 'pmsMaterialCode' },
  { label: '服务名称', width: '90', prop: 'pmsMaterialName' },
  { label: '规格', width: '90', prop: 'formPattern' },
  { label: '单位', width: '90', prop: 'unit' },
  { label: '数量', width: '90', prop: 'mdseNum' },
  { label: '不含税单价(元)', width: '90', prop: 'price' },
  { label: '不含税总价(元)', width: '90', prop: 'equipSum' },
  { label: '税率(%)', width: '90', prop: 'mdseTaxRate' },
  { label: '税额(元)', width: '90', prop: 'mdseTax' },
  { label: '含税总价（元）', width: '90', prop: 'equipTaxSum' }
]

export default {
  name: 'AcceptMangeDetail',
  components: {
    TCollapse,
    MyTable,
    FooterButton,
    JnPrjDetail,
    JnSiteDetail,
    JnProprietaryDetail
  },
  data() {
    return {
      junNanUrl: process.env.VUE_APP_JUNNAN_IFRAME_URL,
      fileUrl: process.env.VUE_APP_ZHONGRUAN_URL,
      loginData: {}, // 本地存储存储
      // okDisb: false, // 按钮默认可点击
      promiseTextShow: true, // 按钮展示承诺div,提交,确认
      proprietaryInfoSrc: '',
      fuJianSrc: '',
      siteInfoSrc: '',
      buttonDisable: [],
      selectList: {},
      Proprietarylist: {},
      basicList: {}, // 基本信息
      prjId: '',
      prjType: '',
      lcList: '',
      urlList: {},
      btnConfig: 'F', //  A:默认，B：下载附件  C：默认+全览  D:下载附件+全览  E：默认+全览+数字图纸   F：补传
      promiseOptions: [
        {
          // 是否建议结算审计必审
          value: '0',
          label: '否'
        },
        {
          value: '1',
          label: '是'
        }
      ],
      promiseValue: '',
      promiseRadio: '', // 承诺
      colOption,
      colOptionTwo,
      activeName: '1',
      dicLists: {}, // 下拉框字典选项集合
      tableData: [], // 物资明细
      tableDataTwo: [], // 服务明细
      returnTypeVal: '',
      apiEnmu: {
        1: 'getAdjustmentSituation',
        2: 'queryAdjustServList'
      },
      promiseRadioDisb: false,
      promiseDisb: false
    }
  },
  async created() {
    const { prjId, pushPerson, ifGotoShManager, workItemId, ifPush } = getQueryObject()
    this.urlList = {
      prjId,
      workItemId,
      pushPerson,
      ifPush,
      ifGotoShManager
    }
    this.prjId = this.urlList.prjId
    this.loginData = JSON.parse(sessionStorage.getItem('SET_LOGINDATA')) // 获取登录用户信息
    if (this.urlList.workItemId) {
      // 待办时候进来用workItemId,查询用的数据
      const { data } = await getWFWorkItem({ workItemId: this.urlList.workItemId })
      this.lcList = data // 获取流程参数信息
    }
    await this.ifarmSrcPram()
    await this.getAdjustmentSituation()
    this.showButton()
    //
    if (this.queryPushAuditList.isPush === '3') {
      console.log(this.queryPushAuditList.isPush, '进了啊1')
      this.promiseTextShow = false // 隐藏是否建议结算审计必审+我承诺
      if ((this.queryPushAuditList.pushPerson === this.loginData.staffId || this.queryPushAuditList.fieldProjectManager === this.loginData.staffId)) {
        this.buttonDisable = ['countermand', 'close']
        this.buttonDisable = workItemId ? ['close'] : ['countermand', 'close']
      } else {
        this.buttonDisable = ['close']
      }
    }
  },
  async mounted() {
    this.getList() // 获取基本信息
  },
  methods: {
    handleClick(val, params) {
      this[this.apiEnmu[val]](params)
    },
    // 物资明细信息
    async getAdjustmentSituation() {
      const { data } = await queryAdjustEquipsList({ prjId: this.prjId, bizSeq: '', isPush: this.queryPushAuditList.isPush, returnType: this.returnTypeVal })
      this.tableData = data
    },
    // 服務明细信息
    async queryAdjustServList() {
      const { data } = await queryAdjustServListNew({ prjId: this.prjId, bizSeq: '', isPush: this.queryPushAuditList.isPush, returnType: this.returnTypeVal })
      this.tableDataTwo = data
    },
    // 2024-10-09 阻断问题if过多解决方案
    optimizeNewOne() {
      return this.urlList.ifGotoShManager === null || this.urlList.ifGotoShManager === '' || this.urlList.ifGotoShManager === 'null'
    },
    // 2024-10-09 阻断问题if过多解决方案
    optimizeNewTwo() {
      // ifGotoShmanager字段  待办进来->进来传null
      if (this.queryPushAuditList.isPush === '0' || this.queryPushAuditList.isPush === '1') {	// 未送审
          // this.okDiShow = false // 隐藏确认按钮？？？？？？？？
          this.buttonDisable = ['submit', 'close'] // *new隐藏撤回按钮
        } else {
          this.buttonDisable = ['close'] // 隐藏提交按钮
          // this.buttonDisable = ['countermand', 'close'] /
        }
    },
     // 2024-10-09 阻断问题if过多解决方案
     optimizeNewThree() {
      if (this.optimizeNewFour()) {
          console.log('走进1')
          this.buttonDisable = ['submit', 'close'] // *new隐藏撤回按钮== 2.0 新条件
        } else if (this.optimizeNewFive()) { // 待办的时候ifPush不用传参
          // this.okDiShow = false // 隐藏确认按钮？？？？？？？？
          console.log('走进2')
          this.buttonDisable = ['submit', 'close'] // *new隐藏撤回按钮
        } else if (this.optimizeNewSix()) {	// 退审重新确认 且 校验项目管理岗 且 项目管理岗等于当前登录人
          // this.okDiShow = false // 隐藏确认按钮？？？？？？？？
          console.log('走进3')
          this.buttonDisable = ['submit', 'close'] // *new隐藏撤回按钮
        } else {
          console.log('走进4')
          console.log('测试=>', this.queryPushAuditList.pushPerson, this.loginData.staffId, this.queryPushAuditList.fieldProjectManager)
          this.promiseTextShow = false
          this.optimizeNewSeven()
          // this.buttonDisable = ['countermand', 'close'] // 隐藏提交按钮
          // 隐藏是否建议结算审计必审+我承诺
          // this.okDiShow = true // 隐藏确认按钮？？？？？？？？
        }
     },
      // 2024-10-09 阻断问题if过多解决方案
      optimizeNewFour() {
        return this.queryPushAuditList.isPush === '0' && this.returnTypeVal === '9' && this.queryPushAuditList.pushPerson === this.loginData.staffId && this.urlList.ifPush === '4'
      },
       // 2024-10-09 阻断问题if过多解决方案
       optimizeNewFive() {
        return this.queryPushAuditList.isPush === '0' && this.urlList.ifGotoShManager === '1' && this.urlList.ifPush === '4'
       },
       // 2024-10-09 阻断问题if过多解决方案
       optimizeNewSix() {
        return this.queryPushAuditList.isPush === '1' && this.urlList.ifGotoShManager === '1' && (this.queryPushAuditList.pushPerson === this.loginData.staffId || this.queryPushAuditList.fieldProjectManager === this.loginData.staffId)
       },
       // 2024-10-09 阻断问题if过多解决方案
       optimizeNewSeven() {
        if ((this.queryPushAuditList.pushPerson === this.loginData.staffId || this.queryPushAuditList.fieldProjectManager === this.loginData.staffId)) {
            this.buttonDisable = ['countermand', 'close']
          } else {
            this.buttonDisable = ['close']
          }
       },
    showButton(infos) {
      /*	2021-04-16 按钮展示逻辑修改：
          流程进入 、 未送审/退审重新确认：展示调接口按钮
          流程进入 、 补充订单送审/其他：展示不调接口按钮
          非流程进入、退审：展示调接口按钮
          非流程进入、其他：不展示按钮
      */
      if (this.optimizeNewOne()) {	// 流程进入
        this.optimizeNewTwo()
      } else {
        /*	2021-04-19 按钮展示逻辑修改：将调用接口逻辑移到结算调整流程下一步
          流程进入：展示不调接口按钮
          非流程进入、退审：展示调接口按钮
          非流程进入、其他：不展示按钮
        */
        this.optimizeNewThree()
      }
    },
    async getList() {
      window.addEventListener('message', (event) => {
        const base_url = ''
        if (event.origin === base_url) {
          return
        }
        if (event.data.type === 'attachment') {
          this.$refs.myIframeFjRef.style.height = event.data.height + 'px'
          // console.log('附件高度')
        }
      })
    },
    // ifarm src 传参
    async ifarmSrcPram() {
      await getPrjDetail({ prjId: this.prjId }).then(res => {
        this.basicList = res.data // 获取基本信息
        this.prjType = this.basicList.prjType
      })
      await queryPushAudit({ prjId: this.prjId }).then(res => {
        this.queryPushAuditList = res.data // 获取获取审状态
        if (this.queryPushAuditList.returnType) {
          this.returnTypeVal = this.queryPushAuditList.returnType
        } else {
          this.returnTypeVal = ''
        }
      })
      var iframeParams = {
        prjType: this.basicList.prjType,
        nodeId: this.lcList.activityDefID, // activityDefID 流程节点ID
        buildModes: this.basicList.buildModes,
        towerType: '0',
        roomType: '0',
        prjId: this.basicList.prjId,
        prjStage: 'Q',
        fileSupplierCode: '', // 供应商接口
        isChange: '0', // 默认传0
        operateType: '1', // 默认传1
        btnConfig: this.btnConfig
      }
      // 附件信息
      if (this.urlList.workItemId) {
        // 待办地址
        this.fuJianSrc = `${this.fileUrl}attachmentInfoTodo?prjType=${iframeParams.prjType}&nodeId=${iframeParams.nodeId}&buildModes=${iframeParams.buildModes}&towerType=${iframeParams.towerType}&roomType=${iframeParams.roomType}&prjId=${iframeParams.prjId}&prjStage=${iframeParams.prjStage}&fileSupplierCode=${iframeParams.fileSupplierCode}&isChange=${iframeParams.isChange}&operateSystem=${iframeParams.operateSystem}&operateType=${iframeParams.operateType}&btnConfig=${iframeParams.btnConfig}&projectId=${iframeParams.prjId}`
      } else {
        // 综合查询->项目操作 nodeId=sett_03 写死
        this.fuJianSrc = `${this.fileUrl}attachmentInfoTodo?prjType=${iframeParams.prjType}&nodeId=sett_03&buildModes=${iframeParams.buildModes}&towerType=${iframeParams.towerType}&roomType=${iframeParams.roomType}&prjId=${iframeParams.prjId}&prjStage=${iframeParams.prjStage}&fileSupplierCode=${iframeParams.fileSupplierCode}&isChange=${iframeParams.isChange}&operateSystem=${iframeParams.operateSystem}&operateType=${iframeParams.operateType}&btnConfig=${iframeParams.btnConfig}&projectId=${iframeParams.prjId}`
      }
    },
    // 撤回
    revocation() {
      this.$confirm(`撤回成功后会再次重新走结算流程,请确认！`, '提示', {
        confirmButtonText: '是',
        cancelButtonText: '否',
        cancelButtonClass: 'pms-zr-button',
        confirmButtonClass: 'pms-zr-button-primary',
        type: 'warning'
      }).then(() => {
        queryIfRetractAudit({ prjId: this.prjId, bizSeq: '' }).then(res => {
          if (+res.code === 200) {
            this.$alert(`${res.message}`, '提示', {
              confirmButtonText: '确定',
              type: 'success',
              showClose: false,
              callback: action => {
                this.handleClose()
              }
            })
          }
        })
      })
    },
    // 提交
    async updateDatas(ifPush) {
      console.log(this.promiseRadio, this.promiseValue, '提交')
      if (!this.promiseValue) {
        this.$message.warning(
          '"是否建议结算审计必审"信息未完善，请在页面完成选择后在提交'
        )
        return
      }
      var isAudit = this.promiseValue // 是否必审
      var isEnd1 = this.promiseRadio // 我承诺：
      if (isEnd1) {
        // 勾选 我承诺
        this.$confirm('请再次确认订单结算金额与项目资料是否正确、完整，提交后审计系统将以此进行结算审计！' +
          '若订单信息不正确，刷新页面（关闭后再次打开页面）后系统会重新获取商合订单信息详情。' +
          '若多次操作后订单信息仍不正确请咨询商合交易系统进行核实（提供项目编码与订单号）。', '系统提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          customClass: 'messageBox',
          cancelButtonClass: 'pms-zr-button',
          confirmButtonClass: 'pms-zr-button-primary',
          closeOnClickModal: false
        }).then(async() => {
          const parsmsObj = { prjId: this.prjId, isAudit: isAudit }
          updateAduitDatas(parsmsObj).then(res => {
            if (+res.code === 200) {
              this.$alert(res.message, '提示', {
                confirmButtonText: '确定',
                type: 'success',
                callback: action => {
                  this.handleClose()
                }
              })
            }
          })
        })
      } else {
        this.$message.warning('"我承诺区域信息"未确认，请在页面完成选择后在提交')
      }
    },
    // 关闭
    handleClose() {
      clonePage()
    }
  }
}
</script>

<style lang="scss" scoped>
.el-collapse {
  margin-bottom: 15px;
}

.el-collapse-item {
  box-shadow: 0px 0px 6px 0px rgba(191, 192, 192, 0.52);
  /* 调整各个item之间的距离为20px */
  /* border: 1px; */
}

.el-collapse-item__wrap {
  padding: 0 20px;
  /* 为el-collapse-item的内容添加20像素的padding */
}

.el-collapse-item__header {
  padding-left: 20px;
  font-size: 14px;
  color: #333333;
  letter-spacing: 0;
  font-weight: 600;
}

.item_icon {
  width: 6px;
  background: rgb(235, 75, 75);
  height: 15px;
  margin-right: 10px;
  border-radius: 10px;
}

::v-deep .content-box {
  width: 100%;
  border-radius: 3px;
  font-size: 12px;
  font-weight: 400;
  // line-height: 28px;
}

/* 承诺class */
.borderStyle {
  font-size: 14px;
  border: 1px solid #ebeef5;
  margin-bottom: 15px;
  margin-top: 0;
  padding: 20px 0;

  .promiseText {
    padding: 20px;

    .promiseBot {
      margin-bottom: 10px;
    }

    .red {
      color: red;
    }
  }
}

::v-deep.centerBox {
  margin-top: 0px;
}

::v-deep .el-input--suffix .el-input__inner {
  height: 20px;
}

::v-deep .el-input__icon {
  line-height: 20px;
}

.textCen {
  text-align: center;
}

::v-deep .el-table {
  overflow-y: auto;
  // height: 300px;
}
</style>
<style>
.messageBox {
  width: 660px;
}
</style>
